import { ipcMain as p, app as t, BrowserWindow as r } from "electron";
import { fileURLToPath as f } from "node:url";
import o from "node:path";
import * as m from "fs";
const i = o.dirname(f(import.meta.url));
process.env.APP_ROOT = o.join(i, "..");
const s = process.env.VITE_DEV_SERVER_URL, E = o.join(process.env.APP_ROOT, "dist-electron"), a = o.join(process.env.APP_ROOT, "dist");
process.env.VITE_PUBLIC = s ? o.join(process.env.APP_ROOT, "public") : a;
let e;
function l() {
  e = new r({
    icon: o.join(process.env.VITE_PUBLIC, "electron-vite.svg"),
    webPreferences: {
      preload: o.join(i, "preload.mjs"),
      nodeIntegrationInWorker: !0,
      contextIsolation: !1,
      nodeIntegration: !0
    }
  }), e.setMenu(null), e.webContents.openDevTools(), e.webContents.on("did-finish-load", () => {
    e == null || e.webContents.send("main-process-message", (/* @__PURE__ */ new Date()).toLocaleString());
  }), s ? e.loadURL(s) : e.loadFile(o.join(a, "index.html"));
}
p.handle("read-file", async (c, d) => {
  try {
    const n = o.resolve(d);
    return { success: !0, data: await m.promises.readFile(n, "utf-8") };
  } catch (n) {
    return console.error(n), { success: !1, error: n };
  }
  console.log(c);
});
t.on("window-all-closed", () => {
  process.platform !== "darwin" && (t.quit(), e = null);
});
t.on("activate", () => {
  r.getAllWindows().length === 0 && l();
});
t.whenReady().then(l);
export {
  E as MAIN_DIST,
  a as RENDERER_DIST,
  s as VITE_DEV_SERVER_URL
};
